<template>
  <el-card class="box-card">
    <el-steps
      style="margin-top: 18px"
      :space="200"
      :active="currentStep"
      finish-status="success"
      simple
    >
      <el-step title="基本信息" :icon="Edit" @click="currentStep = 0" />
      <el-step title="课程图片" :icon="Picture" @click="currentStep = 1" />
      <el-step
        title="销售及活动信息"
        :icon="ShoppingCart"
        @click="currentStep = 2"
      />
      <el-step title="课程详情" :icon="Document" @click="currentStep = 3" />
    </el-steps>
    <el-form :model="courseInfo" label-width="120">
      <div v-show="currentStep === 0" style="margin-top: 26px"></div>
      <div v-show="currentStep === 1">
        <el-form-item label="课程封面：" style="margin-top: 30px">
          <!-- 图片上传 -->
          <el-upload action="#" list-type="picture-card" :auto-upload="false">
            <el-icon><Plus /></el-icon>

            <template #file="{ file }">
              <div>
                <img
                  class="el-upload-list__item-thumbnail"
                  :src="file.url"
                  alt=""
                />
                <span class="el-upload-list__item-actions">
                  <span
                    class="el-upload-list__item-preview"
                    @click="handlePictureCardPreview(file)"
                  >
                    <el-icon><zoom-in /></el-icon>
                  </span>
                  <span
                    v-if="!disabled"
                    class="el-upload-list__item-delete"
                    @click="handleDownload(file)"
                  >
                    <el-icon><Download /></el-icon>
                  </span>
                  <span
                    v-if="!disabled"
                    class="el-upload-list__item-delete"
                    @click="handleRemove(file)"
                  >
                    <el-icon><Delete /></el-icon>
                  </span>
                </span>
              </div>
            </template>
          </el-upload>
        </el-form-item>
      </div>
      <div v-show="currentStep === 2">销售及活动信息</div>
      <div v-show="currentStep === 3">课程详情</div>
    </el-form>

    <!-- <el-button style="margin-top: 20px" @click="next">Next step</el-button> -->
  </el-card>
</template>

<script setup lang="ts">
import { Edit, ShoppingCart, Picture, Document } from '@element-plus/icons-vue'
import { reactive, ref, onMounted } from 'vue'
import { getCategory } from '@/api/category/index'

let currentStep = ref(0)
let courseInfo = reactive({
  title: '',
  lesson_num: 0,
  price: 0
})
let data = ref([])

//======以下为上传课程图片相关代码=====
//图片上传成功之后的回调
const dialogImageUrl = ref('')
const dialogVisible = ref(false)
const disabled = ref(false)
import type { UploadFile } from 'element-plus'

const handleRemove = (file: UploadFile) => {
  console.log(file)
}

const handlePictureCardPreview = (file: UploadFile) => {
  dialogImageUrl.value = file.url!
  dialogVisible.value = true
}

const handleDownload = (file: UploadFile) => {
  console.log(file)
}

onMounted(async () => {
  // 在组件挂载后执行的代码
  const res = await getCategory()
  //  console.log(res.data)
  data.value = res.data
})
</script>

<style scoped>
.el-step {
  cursor: pointer;
}
/* .el-form{
  padding:0px 180px 0px 0px;
} */
.form-bottom-btn {
  display: flex;
  justify-content: center;
}

.avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>
